package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.vo.RoomLeaseVO;
import com.ruoyi.park.service.IBuiRoomLeaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 房源租赁Controller
 *
 * @author cjie
 * @date 2021-07-20
 */
@Api(tags = " 房源租赁")
@RestController
@RequestMapping("/buiRoomLease")
public class BuiRoomLeaseController extends BaseController {
    @Autowired
    private IBuiRoomLeaseService buiRoomLeaseService;

    /**
     * 查询房源租赁列表
     */
    @ApiOperation(value="查询房源租赁列表", notes="查询房源租赁列表")
    @PreAuthorize(hasPermi = "park:buiRoomLease:list")
    @GetMapping("/list")
    public TableDataInfo list(RoomLeaseVO roomLeaseVO) {
        startPage();
        List<RoomLeaseVO> list = buiRoomLeaseService.selectBuiRoomLeaseList(roomLeaseVO);
        return getDataTable(list);
    }

    /**
     * 导出房源租赁列表
     */
    @ApiOperation(value="导出房源租赁列表", notes="导出房源租赁列表")
    @PreAuthorize(hasPermi = "park:buiRoomLease:export")
    @Log(title = "房源租赁", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RoomLeaseVO roomLeaseVO) throws IOException {
        List<RoomLeaseVO> list = buiRoomLeaseService.selectBuiRoomLeaseList(roomLeaseVO);
        ExcelUtil<RoomLeaseVO> util = new ExcelUtil<RoomLeaseVO>(RoomLeaseVO.class);
        util.exportExcel(response, list, "房源租赁数据");
    }
    /**
     * 获取房源租赁详细信息
     */
    @ApiOperation(value="获取房源租赁详细信息", notes="获取房源租赁详细信息")
    @PreAuthorize(hasPermi = "park:buiRoomLease:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buiRoomLeaseService.selectRoomLeaseByRoomId(id));
    }

}
